package com.df.common.exception;

/**
 * 自定义异常类 Created by  on 2019/8/19.
 */
public class GlobalException extends RuntimeException {

    protected String code;
    protected String message;

    public GlobalException() {
        super();
        this.code = ErrorCode.UNKNOWN.code();
        this.message = ErrorCode.UNKNOWN.msg();
    }

    public GlobalException(IExceptionType et) {
        super();
        this.code = et.getCode();
        this.message = et.getMessage();
    }

    public GlobalException(Throwable cause) {
        super(cause);
        this.code = ErrorCode.UNKNOWN.code();
        this.message = cause.getMessage();
    }

    public GlobalException(String message) {
        super(message);
        this.code = ErrorCode.UNKNOWN.code();
        this.message = message;
    }

    public GlobalException(IExceptionType et, String message) {
        super(message);
        this.code = et.getCode();
        this.message = message;
    }

    public GlobalException(IExceptionType et, Throwable exp) {
        super(exp);
        this.code = et.getCode();
        this.message = exp.getMessage();
    }

    public GlobalException(ErrorCode errorCode, Throwable cause) {
        super(cause);
        this.code = errorCode.code();
        this.message = cause.getMessage();
    }

    public GlobalException(ErrorCode errorCode, String message) {
        super(message);
        this.code = errorCode.code();
        this.message = message;
    }

    public GlobalException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
